package com.ruoyi.system.web.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Airport;
import com.ruoyi.system.service.IAirportService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 机场Controller
 * 
 * @author ruoyi
 * @date 2023-05-10
 */
@RestController
@RequestMapping("/system/airport")
public class AirportController extends BaseController
{
    @Autowired
    private IAirportService airportService;

    /**
     * 查询机场列表
     */
    @PreAuthorize("@ss.hasPermi('system:airport:list')")
    @GetMapping("/list")
    public TableDataInfo list(Airport airport)
    {
        startPage();
        List<Airport> list = airportService.selectAirportList(airport);
        return getDataTable(list);
    }

    /**
     * 导出机场列表
     */
    @PreAuthorize("@ss.hasPermi('system:airport:export')")
    @Log(title = "机场", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Airport airport)
    {
        List<Airport> list = airportService.selectAirportList(airport);
        ExcelUtil<Airport> util = new ExcelUtil<Airport>(Airport.class);
        util.exportExcel(response, list, "机场数据");
    }

    /**
     * 获取机场详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:airport:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(airportService.selectAirportById(id));
    }

    /**
     * 新增机场
     */
    @PreAuthorize("@ss.hasPermi('system:airport:add')")
    @Log(title = "机场", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Airport airport)
    {
        return toAjax(airportService.insertAirport(airport));
    }

    /**
     * 修改机场
     */
    @PreAuthorize("@ss.hasPermi('system:airport:edit')")
    @Log(title = "机场", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Airport airport)
    {
        return toAjax(airportService.updateAirport(airport));
    }

    /**
     * 删除机场
     */
    @PreAuthorize("@ss.hasPermi('system:airport:remove')")
    @Log(title = "机场", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(airportService.deleteAirportByIds(ids));
    }
}
